/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jl.tools.stkeditor.generate;

import com.jl.tools.stkeditor.exception.DataNotMatchCodingScheamException;
import com.jl.util.HexUtil;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author LuHongjun
 */
public final class ASCIICode implements Code {

  private String oneline;

  public ASCIICode(String oneline) {
    this.oneline = oneline;
  }

  @Override
  public List<String> getCode()throws DataNotMatchCodingScheamException{
    List<String> l = new ArrayList<String>();
    for (int i = 0; i < oneline.length(); i++) {
      int value = oneline.codePointAt(i);
      if ((value & 0xFF00) != 0) {
        throw new DataNotMatchCodingScheamException("Data Wrong,Be Careful Of The Coding Scheam,May be Not The ASCII char");
      } else {
        l.add(HexUtil.toHexXX(value));
      }
    }
    return l;
  }

  @Override
  public int getLength() {
    return oneline.length();
  }
}
